{% extends "personal_center/zichan_base.html" %}
{#物料种类列表展示页#}

{% block page_link %}
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/index.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/common.css">
    <script type="text/javascript" src="../../static/personal_center/js/index.js"></script>
{% endblock %}

{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        .tab_top {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            display: inline-block;
            cursor: pointer;
        }

        .shade {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(36, 36, 36, 0.5);
            display: none;
            z-index: 10000;
        }

    </style>
{% endblock %}

{% block right_content %}
    <div id="add_the_kind_of_product"
         style="padding: 15px;z-index:1;position: absolute; display: none; width: 30%; height: 45%; background: #f7f7f7; border:solid 1px #dddddd; border-radius: 15px; top: 26%;left: 44%; box-shadow: 3px 3px #e9eae8">
        <div style="text-align: right;">
            <span style="cursor: pointer" onclick="close_win()">✖</span>
        </div>
        <div style="text-align: center">
            <h4>新增物料类型</h4>
        </div>
        <div style="margin: 7% 10% ">定义编号：<input id="get_order" type="text"
                                                 style="padding-left:5px; width: 75%; border:none; border-bottom: solid 2px #000000;background: #f7f7f7"
                                                 disabled value="{{ number }}"></div>
        <div style="margin: 7% 10% ">输入名称：<input id="get_name" type="text" placeholder="请输入名称"
                                                 style="padding-left:5px; width: 75%; border:none; border-bottom: solid 2px #000000;background: #f7f7f7">
        </div>
        <div style="margin: 7% 10% ">定义单位：<input id="get_quantifier" type="text" placeholder="例如：个、件、箱等..."
                                                 style="padding-left:5px; width: 75%; border:none; border-bottom: solid 2px #000000;background: #f7f7f7">
        </div>
        <div style="text-align: center; margin-top: 15%">
            <button style="width: 100px;height: 30px;background: #1E90FF;color: #FFFFFF;border: none;border-radius: 3px;cursor: pointer"
                    onclick="found_kind()">确定
            </button>
        </div>
    </div>
    <div id="remind" class="shade">
        <div id="del_remind"
             style="position: absolute;width: 400px;height: 250px;top: 25%;left: 45%;box-shadow: 0 0 4px #999;background: white;border-radius: 3px;">
            <div id="box_remind"
                 style="width: 100%;height: 35px;border-bottom: #cfcfcf solid 1px;line-height: 35px;padding-left: 10px;cursor: move;">
                <p style="display: inline-block;"></p>
                <p onclick="close_remind()"
                   style="display: inline-block;float: right;cursor: pointer;width: 35px;height: 35px;line-height: 35px;text-align: center;">
                    <i class="iconfont icon-quchu"></i>
                </p>
            </div>
            <div style="width: 100%;height: 170px;border-bottom: #cfcfcf solid 1px;padding: 20px;text-align: center;">
                <div style="width: 100%;height: 100px;line-height: 40px;">
                    <img src="../../static/personnel/img/jinggao.png" alt="" style="width: 100px;height: 100px;">
                </div>
                <div style="width: 100%;height: 40px;line-height: 40px;">
                    检测到删除操作！是否执行？
                </div>
            </div>
            <div style="width: 100%;height: 45px;text-align: right;padding-right: 10px;">
                <button id="cancel-but" onclick="close_remind()"
                        style="width: 70px;height: 29px;margin-top: 8px;border: #00a0e9 solid 1px;background: #00a0e9;color: white;border-radius: 3px;display: inline-block;vertical-align: top;">
                    取消
                </button>
                <button id="remind-but"
                        style="width: 70px;height: 29px;margin-top: 8px;border: red solid 1px;background: red;color: white;border-radius: 3px;display: inline-block;vertical-align: top;margin-left: 10px;">
                    确认
                </button>
            </div>
        </div>
    </div>
    <div style="display: inline-block;vertical-align: top;width: 100%;height: 100%;">
        <div class="headline">
            <div class="tab_top ">物料清单</div>
            <div style="line-height: 30px; text-align: right;display: inline-block; position: relative;left: 85%">
                <a style="width: 100px; height: 30px; background: #1E90FF; border-radius: 4px;color: #FFFFFF;border: none; text-align: center"
                   type="button" onclick="add_kind_of_product()">
                    新增物料</a>
            </div>
        </div>
        <div id="my_application" style="width: 100%;height: 95.3%;overflow: auto;background-color: white;">
            <div class="right-box" style="width: 100%;height: 100%;margin-top: 0;">
                <div style="height: 100%;width: 100%;overflow: auto;border-bottom: #cccccc solid 1px;background-color: white;">
                    <section class="grid-main">
                        <table id="main_table"></table>
                    </section>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/administrative/js/layer.js"></script>
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("zichan").className = "add_class";
            document.getElementById("product_management").className = "add-nav-active";
        };

        const gridManagerName = "test",
            TYPE_MAP = {1: "HTML/CSS", 2: "nodeJS", 3: "javaScript", 4: "前端鸡汤", 5: "PM Coffee", 6: "前端框架", 7: "前端相关"},
            GM_PUBLISH_METHOD_MAP = {
                init: {key: "init", relyInit: !1, title: "初始化", code: 'demo1.initGM(document.querySelector("table"));'},
                get: {key: "get", relyInit: !0, title: "获取表格的实时配置信息", code: `GridManager.get('${gridManagerName}');`},
                version: {key: "version", relyInit: !1, title: "获取当前GridManager的版本号", code: "GridManager.version;"},
                getLocalStorage: {
                    key: "getLocalStorage",
                    relyInit: !0,
                    title: "获取表格用户记忆",
                    code: `GridManager.getLocalStorage('${gridManagerName}');`
                },
                resetLayout: {
                    key: "resetLayout",
                    relyInit: !0,
                    title: "重置表格布局",
                    code: `GridManager.resetLayout('${gridManagerName}', '800px', '500px');`
                },
                clear: {
                    key: "clear",
                    relyInit: !0,
                    title: "清除表格记忆数据",
                    code: `GridManager.clear('${gridManagerName}');`
                },
                getTableData: {
                    key: "getTableData",
                    relyInit: !0,
                    title: "获取指定tr所使用的数据",
                    code: `GridManager.getTableData('${gridManagerName}');`
                },
                getRowData: {
                    key: "getRowData",
                    relyInit: !0,
                    title: "获取指定tr所使用的数据",
                    code: `GridManager.getRowData('${gridManagerName}', document.querySelector("table[grid-manager=${gridManagerName}] tbody tr"));`
                },
                updateRowData: {
                    key: "updateRowData",
                    relyInit: !0,
                    title: "更新指定行所使用的数据",
                    code: `GridManager.updateRowData('${gridManagerName}', 'id', {id: 112, title: 'ccc'});`
                },
                updateTreeState: {
                    key: "updateTreeState",
                    relyInit: !0,
                    title: "更新树的展开状态",
                    code: `GridManager.updateTreeState('${gridManagerName}', true);`
                },
                setSort: {
                    key: "setSort",
                    relyInit: !0,
                    title: "手动设置排序",
                    code: `GridManager.setSort('${gridManagerName}', {createDate: 'ASC'});`
                },
                setConfigVisible: {
                    key: "setConfigVisible",
                    relyInit: !0,
                    title: "设置表头配置区域可视状态",
                    code: `GridManager.setConfigVisible('${gridManagerName}', true);`
                },
                setLineHeight: {
                    key: "setLineHeight",
                    relyInit: !0,
                    title: "配置行的高度",
                    code: `GridManager.setLineHeight('${gridManagerName}', '70px');`
                },
                showTh: {
                    key: "showTh",
                    relyInit: !0,
                    title: "设置列为可视状态",
                    code: `GridManager.showTh('${gridManagerName}', 'pic');`
                },
                hideTh: {
                    key: "hideTh",
                    relyInit: !0,
                    title: "设置列为隐藏状态",
                    code: `GridManager.hideTh('${gridManagerName}', 'pic');`
                },
                exportGrid: {
                    key: "exportGrid",
                    relyInit: !0,
                    title: "导出指定表格",
                    code: `GridManager.exportGrid('${gridManagerName}', 'demo中使用的导出').then(res=>{console.log('success')}).catch(err=>{console.error('error', err)});`
                },
                setQuery: {
                    key: "setQuery",
                    relyInit: !0,
                    title: "更改在生成组件时所配置的参数query",
                    code: `GridManager.setQuery('${gridManagerName}', {'userName':'baukh','sex':'男'});`
                },
                setAjaxData: {
                    key: "setAjaxData",
                    relyInit: !0,
                    title: "用于再次配置ajaxData数据",
                    code: `GridManager.setAjaxData('${gridManagerName}', {data: [{title: '通过setAjaxData动态添加的数据，其它项为空'}], totals: 1});`
                },
                refreshGrid: {
                    key: "refreshGrid",
                    relyInit: !0,
                    title: "刷新表格",
                    code: `GridManager.refreshGrid('${gridManagerName}');`
                },
                renderGrid: {
                    key: "renderGrid",
                    relyInit: !0,
                    title: "渲染表格",
                    code: `GridManager.renderGrid('${gridManagerName}');`
                },
                getCheckedTr: {
                    key: "getCheckedTr",
                    relyInit: !0,
                    title: "获取当前选中的行",
                    code: `GridManager.getCheckedTr('${gridManagerName}');`
                },
                getCheckedData: {
                    key: "getCheckedData",
                    relyInit: !0,
                    title: "获取选中行的渲染数据",
                    code: `GridManager.getCheckedData('${gridManagerName}');`
                },
                setCheckedData: {
                    key: "setCheckedData",
                    relyInit: !0,
                    title: "设置选中的数据",
                    code: `GridManager.setCheckedData('${gridManagerName}', [GridManager.getTableData('${gridManagerName}')[1]]);`
                },
                cleanData: {
                    key: "cleanData",
                    relyInit: !0,
                    title: "清除指定表格数据",
                    code: `GridManager.cleanData('${gridManagerName}');`
                },
                print: {key: "print", relyInit: !0, title: "打印当前页", code: `GridManager.print('${gridManagerName}');`},
                showRow: {
                    key: "showRow",
                    relyInit: !0,
                    title: "显示隐藏行",
                    code: `GridManager.showRow('${gridManagerName}', 1);`
                },
                hideRow: {
                    key: "hideRow",
                    relyInit: !0,
                    title: "隐藏行",
                    code: `GridManager.hideRow('${gridManagerName}', 1);`
                },
                showLoading: {
                    key: "showLoading",
                    relyInit: !0,
                    title: "显示加载中",
                    code: `GridManager.showLoading('${gridManagerName}');`
                },
                hideLoading: {
                    key: "hideLoading",
                    relyInit: !0,
                    title: "隐藏加载中",
                    code: `GridManager.hideLoading('${gridManagerName}', 300);`
                },
                destroy: {
                    key: "destroy",
                    relyInit: !0,
                    title: "消毁指定的GridManager实例",
                    code: `GridManager.destroy('${gridManagerName}');`
                }
            }, arg = {
                gridManagerName: "test",
                width: "100%",
                height: "100%",
                autoOrderConfig: {fixed: "left"},
                checkboxConfig: {key: "id", fixed: "left"},
                supportAjaxPage: !0,
                sortMode: "single",
                supportMenu: !0,
                menuHandler: e => (e.unshift({
                    content: "自定义菜单", line: !0, onClick: e => {
                        alert(e)
                    }
                }), e),
                useCellFocus: !0,
                useHideRow: !0,
                supportMoveRow: !0,
                moveRowConfig: {
                    key: "priority", useSingleMode: !0, fixed: "left", handler: (e, t) => {
                        console.log(e, t)
                    }
                },
                disableCache: !1,
                ajaxData: function (e, t) {
                    var local_host = window.location.host;          // 获取当前IP
                    return "/personal-center/product_kind_list_view"
                },
                exportConfig: {
                    fileName: e => {
                        const t = new Date;
                        let a = `${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()}`;
                        for (let t in e) a = `${a}-${t}=${e[t]}`;
                        return a
                    }, suffix: "xls"
                },
                ajaxType: "POST",
                checkedBefore: function (e, t, a) {
                    return console.log("checkedBefore==", e, t, a), a && 90 === a.id && alert("该节点在checkedBefore中配置为不可选"), a && 90 !== a.id
                },
                checkedAfter: function (e, t, a) {
                    console.log("checkedAfter==", e, t, a)
                },
                checkedAllBefore: function (e, t) {
                    console.log("checkedAllBefore==", e, t)
                },
                checkedAllAfter: function (e, t) {
                    console.log("checkedAllAfter==", e, t)

                },
                sortingBefore: function (e) {
                    console.log("sortingBefore", e)
                },
                sortingAfter: function (e) {
                    console.log("sortingAfter", e)
                },
                ajaxBeforeSend: function (e) {
                    console.log("ajaxBeforeSend")
                },
                ajaxSuccess: function (e) {
                    console.log("ajaxSuccess")
                },
                ajaxError: function (e) {
                    console.log("ajaxError")
                },
                ajaxComplete: function (e) {
                    console.log("ajaxComplete")
                },
                adjustBefore: e => {
                    console.log("adjustBefore=>", e)
                },
                adjustAfter: e => {
                    console.log("adjustAfter=>", e)
                },
                responseHandler: e => (e.data.forEach((e => {
                    e.priority = e.id
                })), e),
                rowRenderHandler: (e, t) => e,
                emptyTemplate: e => `<div style="text-align: center;">${e.query.title ? "搜索为空" : "暂无数据"}</div>`,
                columnData: [
                    {
                        key: "number",
                        text: "物料编号",
                        align: "center",
                        disableMoveRow: !0
                    }, {
                        key: "name",
                        text: "物料名称",
                        align: "center",
                    }, {
                        key: "unit",
                        text: "单位",
                        align: "center",
                    }, {
                        key: "action",
                        width: "100px",
                        align: "center",
                        fixed: "right",
                        disableMoveRow: !0,
                        disableRowCheck: !0,
                        text: '<span style="color: red">操作</span>',
                        template: (e, t) => `<span class="plugin-action" id="${t.id}" onclick="remind_fuc(this.id)">删除</span>`
                    }]
            }, demo1 = {
                initSearch: function () {
                }, initFN: () => {

                }, initGM: function () {
                    new window.GridManager(table, arg, (e => {
                        console.log("渲染完成后的回调函数:", e), console.log(arg.columnData)
                    }))
                }, editRowData: function (e) {
                    window.GridManager.updateRowData("test", "id", {
                        id: window.parseInt(e.getAttribute("data-id")),
                        lastDate: (new Date).getTime()
                    })
                }
            }, table = document.querySelector("#main_table");
        demo1.initSearch(table), demo1.initGM(table), demo1.initFN();

        // 添加物料模型
        function add_kind_of_product() {
            document.getElementById("add_the_kind_of_product").style.display = 'inline-block';
        }

        function close_win() {
            document.getElementById("add_the_kind_of_product").style.display = 'none';
        }

        function found_kind() {
            var number = $("#get_order").val();
            var name = $("#get_name").val();
            var unit = $("#get_quantifier").val();
            if (!number || !name || !unit) {
                alert("请填写数据！")
                return false
            }
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;
            xhr.open('post', "/personal-center/product_kind_list_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
            xhr.send("number=" + number + "&name=" + name + "&unit=" + unit)
            console.log("number=" + number + "&name=" + name + "&unit=" + unit)
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        alert("创建成功！")
                        document.getElementById("loading").style.display = "none";
                        {#document.getElementById("add_the_kind_of_product").style.display = 'none';#}
                        window.location.href = "/personal-center/product_kind_list_view";
                    }
                }
            }
        }

        function remind_fuc(ele_id) {
            document.getElementById("remind").style.display = "table";
            document.getElementById("remind-but").setAttribute("onclick", "delete_func('" + ele_id + "')")
        }

        function close_remind() {
            document.getElementById("remind").style.display = "none";
        }

        function delete_func(id) {
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;
            xhr.open('post', "/personal-center/delete_product_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
            xhr.send("id=" + id);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonData = JSON.parse(xhr.responseText);
                        if (JsonData["code"] === 200) {
                            alert("提交成功")
                            location.reload()
                        } else {
                            alert(JsonData['message'])
                        }
                        {#document.getElementById("loading").style.display = "none";#}
                    }
                }
            }
        }
    </script>
{% endblock %}